package com.smart.campus.school.service.impl;

import java.util.List;
import com.smart.campus.common.utils.DateUtils;
import com.smart.campus.school.domain.ExamQuestion;
import com.smart.campus.school.service.IExamQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.smart.campus.school.mapper.WrongQuestionMapper;
import com.smart.campus.school.domain.WrongQuestion;
import com.smart.campus.school.service.IWrongQuestionService;
import com.smart.campus.common.core.text.Convert;

/**
 * 错题记录Service业务层处理
 * 
 * @author Zhihe.Li
 * @date 2020-05-25
 */
@Service
public class WrongQuestionServiceImpl implements IWrongQuestionService 
{
    @Autowired
    private WrongQuestionMapper wrongQuestionMapper;
    @Autowired
    private IExamQuestionService questionService;

    /**
     * 查询错题记录
     * 
     * @param id 错题记录ID
     * @return 错题记录
     */
    @Override
    public WrongQuestion selectWrongQuestionById(Long id)
    {
        return wrongQuestionMapper.selectWrongQuestionById(id);
    }

    /**
     * 查询错题记录列表
     * 
     * @param wrongQuestion 错题记录
     * @return 错题记录
     */
    @Override
    public List<WrongQuestion> selectWrongQuestionList(WrongQuestion wrongQuestion)
    {

        List<WrongQuestion> wrongQuestionList = wrongQuestionMapper.selectWrongQuestionList(wrongQuestion);
        for (WrongQuestion question : wrongQuestionList) {
            ExamQuestion examQuestion = questionService.selectExamQuestionById(question.getQuestionId());
            question.setExamQuestion(examQuestion);
        }
        return wrongQuestionList;
    }

    /**
     * 新增错题记录
     * 
     * @param wrongQuestion 错题记录
     * @return 结果
     */
    @Override
    public int insertWrongQuestion(WrongQuestion wrongQuestion)
    {
        wrongQuestion.setCreateTime(DateUtils.getNowDate());
        return wrongQuestionMapper.insertWrongQuestion(wrongQuestion);
    }

    /**
     * 修改错题记录
     * 
     * @param wrongQuestion 错题记录
     * @return 结果
     */
    @Override
    public int updateWrongQuestion(WrongQuestion wrongQuestion)
    {
        wrongQuestion.setUpdateTime(DateUtils.getNowDate());
        return wrongQuestionMapper.updateWrongQuestion(wrongQuestion);
    }

    /**
     * 删除错题记录对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWrongQuestionByIds(String ids)
    {
        return wrongQuestionMapper.deleteWrongQuestionByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除错题记录信息
     * 
     * @param id 错题记录ID
     * @return 结果
     */
    @Override
    public int deleteWrongQuestionById(Long id)
    {
        return wrongQuestionMapper.deleteWrongQuestionById(id);
    }
}
